<?php
if (isset($_COOKIE["user_dailv"])) {
    header("Location: index.php");
}
?>
<?php
if (isset($_POST["reg"])) {
    require 'mysql.php';
    $user = $_POST['user'];
    $email = $_POST['email'];
    $password = md5(mysql_real_escape_string($_POST['password']));
    $sql = "Insert LeVanDai_tbluser values('$user','$email','$password')";
    if (!mysqli_query($link, $sql)) {
        echo "Dang ky khong thanh cong";
    } else {
        echo "Done! - You will be redirected in 3 seconds";
        header("refresh:3; url=login.php");
    }
}
?>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Register</title>
        <script language=JavaScript>
            function checkInput()
            {

            if (document.frmRegister.user.value == "")
            {
            alert("Please enter Username")");
                    document.frmRegister.user.focus();
                    return false;
            }
            if (document.frmRegister.email.value == "")
            {
            alert("Please enter Email")");
                    document.frmRegister.email.focus();
                    return false;
            }
            if (document.frmRegister.password.value == "")
            {
            alert("Please enter Password")");
                    document.frmRegister.password.focus();
                    return false;
            }
            return true;
            }
        </script>
    </head>
    <body style="width: 800px; margin: 20px auto auto auto">
    <body>
        <form name="frmRegister" action="" method="post" onsubmit="return checkInput();">
            Username: <input type="text" name="user">
            <br>
            Email: <input type="text" name="email">
            <br>
            Password: <input type="password" name="password">
            <br>
            <input type="submit" name="reg" value="Dang ky" />            
        </form>        
    </body>
</body>
</html>
